package com.lbssoft.gpsbd.dao.sql;

import org.apache.ibatis.jdbc.SQL;

import com.lbssoft.gpsbd.model.Geofence;
import com.mysql.jdbc.StringUtils;

public class GeofenceSql {
	private static final String TABLE_NAME = "lbs_geofences";

	
	
	public String update(final Geofence geofence) {
		return new SQL(){
			{
				UPDATE(TABLE_NAME);

				// 通过条件 判断是否需要更新该字段
				if (!StringUtils.isNullOrEmpty(geofence.getName())) {
					SET("name = #{name}");
				}

				if (!StringUtils.isNullOrEmpty(geofence.getType())) {
					SET("type = #{type}");
			
				}
				
				if (!StringUtils.isNullOrEmpty(geofence.getArea())) {
					SET("area = #{area}");
			
				}
				if (!StringUtils.isNullOrEmpty(geofence.getDescription())) {
					SET("description = #{description}");
			
				}
				WHERE("id= #{id}");
	
			}
		}.toString();
	}
	
}
